package com.seele.tigerwallet.ui.popupwindow;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import com.seele.tigerwallet.R;
import com.seele.tigerwallet.utils.SeeleFileMap;
import com.seele.tigerwallet.utils.Utils;
import com.seele.tigerwallet.wallet.WalletManager;

public class UpdatePopupWindow  extends PopupWindow implements View.OnClickListener{

    private Context mContext;
    private int mWidth;
    private int mHeight;
    private TextView mCancel;
    private TextView mUpdate;
    private TextView mTitle;
    private TextView mContent;
    private OnClickListener mOnClickListener;
    private static final String TAG = "UpdatePopupWindow";

    public UpdatePopupWindow(Context context) {
        super(context);
        mContext = context;
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.update_popupwindow,null);
        setContentView(view);
        setTouchable(true);
        setFocusable(true);
        calWidthAndHeight(mContext);
        setWidth(mWidth);
        setHeight(mHeight);
        setOutsideTouchable(false);
        setClippingEnabled(false);
        ColorDrawable dw = new ColorDrawable(-00000);
        this.setBackgroundDrawable(dw);
        mCancel = (TextView) view.findViewById(R.id.cancel);
        mCancel.setOnClickListener(this);
        mUpdate = (TextView) view.findViewById(R.id.update);
        mUpdate.setOnClickListener(this);
        mTitle = (TextView) view.findViewById(R.id.tv_title);
        mContent = (TextView) view.findViewById(R.id.tv_content);
    }

    public void setTitle(String title) {
        mTitle.setText(title);
    }

    public void setContent(String content) {
        mContent.setText(content);
    }

    public void showAtLocation(Activity acitivity){
        //this.showAtLocation(acitivity.getWindow().getDecorView(), Gravity.CENTER,0,0);
        this.showAtLocation(acitivity.getWindow().getDecorView(), Gravity.TOP | Gravity.RIGHT,0,0);
    }

    public void setmOnClickListener(OnClickListener listener) {
        this.mOnClickListener = listener;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.cancel) {
            mOnClickListener.onCancel();
        } else if (v.getId() == R.id.update) {
            mOnClickListener.onUpdate();
        }
    }

    public interface OnClickListener{
        public void onCancel();
        public void onUpdate();
    }



    /**
     * 设置PopupWindow的大小
     * @param context
     */
    private void calWidthAndHeight(Context context) {
        WindowManager wm= (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics metrics= new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);

        mWidth=metrics.widthPixels;
        //设置高度为全屏高度的70%
        mHeight= (int) (metrics.heightPixels);
    }


}
